package com.seveneight.baijiesteward.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.MessageBean;
import com.seveneight.baijiesteward.base.MessageEvent;
import com.seveneight.baijiesteward.bean.CardBean;
import com.seveneight.baijiesteward.http.HttpConfig;
import com.seveneight.baijiesteward.utils.GlideLoader;
import com.seveneight.baijiesteward.utils.NumberUtil;
import com.seveneight.baijiesteward.utils.StringFormat;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by user1 on 2018/3/23.
 */

public class CardListAdapter extends ListBaseAdapter<CardBean> {

    public CardListAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_card;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        ImageView iv_bankImg = holder.getView(R.id.iv_bankImg);
        TextView tv_bankName = holder.getView(R.id.tv_bankName);
        TextView tv_cardType = holder.getView(R.id.tv_cardType);
        TextView tv_cardNum = holder.getView(R.id.tv_cardNum);
        ImageView iv_more = holder.getView(R.id.iv_more);
        final CardBean cardBean = mDataList.get(position);
        tv_cardType.setText("借记卡");
        GlideLoader.displayImg(mContext, HttpConfig.SOURCE_URL + cardBean.getIcoUrl(), iv_bankImg);
        if (cardBean.getIsDefault()) {
            tv_bankName.setText(cardBean.getBankName() + "(默认)");
        } else {
            tv_bankName.setText(cardBean.getBankName());
        }
        tv_cardNum.setText(StringFormat.getCardNumber(cardBean.getBankCardNo()));
        iv_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new MessageBean(1, position, cardBean));
            }
        });
    }
}
